package com.cet.designpatterns.factory.factorymethod.order;

import com.cet.designpatterns.factory.factorymethod.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-31 23:06
 **/
public abstract class OrderPizza {

    public OrderPizza() {
        Pizza pizza = null;
        //订购披萨的类型
        String orderType;
        do {
            orderType = getType();
            pizza = createPizza(orderType);
            //输出Pizza制作的过程
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        }while (true);
    }

    /**
     * 定义一个抽象方法，createPizza,让各个工厂子类自己实现
     */
    abstract Pizza createPizza(String orderType);

    // 获取客户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            return strin.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
